package top.shiyiri.service.impl;

import top.shiyiri.dao.UserDao;
import top.shiyiri.dao.impl.UserDaoImpl;
import top.shiyiri.pojo.User;
import top.shiyiri.service.UserService;

/**
 * @author Aunean
 * @date 2022/1/28 19:56
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public void register(User user) {
        userDao.saveUser(user);
    }

    @Override
    public User login(String username, String password) {
        return userDao.queryUserByUsernameAndPassword(username, password);
    }

    @Override
    public boolean existsUsername(String username) {
        if (userDao.queryUserByUsername(username) == null) {
            //等于null表示没查到相同用户名，表示可用
            return false;
        }
        return true;
    }
}
